import wx

import model
#import image_wizard



class SceneEditor(wx.ScrolledWindow):

    def __init__(self, parent):
        super(SceneEditor, self).__init__(parent, style=wx.SUNKEN_BORDER)
        self.SetVirtualSize( (1000,1000) )
        self.SetScrollRate(20,20)


class EditFrame(wx.Frame):

    def __init__(self, parent=None, title="Test"):
        super(EditFrame, self).__init__(parent, -1, title)

        # testbutton
        button = wx.Button(self, -1, "Copy from Clipboard")
        self.Bind(wx.EVT_BUTTON, self.OnCopyButtonClick, button)

        button2 = wx.Button(self, -1, "Load test.png")
        self.Bind(wx.EVT_BUTTON, self.OnLoadButtonClock, button2)

        # sceneeditor
        self.sceneEditor = SceneEditor(self)

        # sizer
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(button, 0, wx.ALL|wx.EXPAND, 5)
        sizer.Add(button2, 0, wx.ALL|wx.EXPAND, 5)
        sizer.Add(self.sceneEditor, 1, wx.EXPAND, 5)
        self.SetSizer(sizer)
        self.Layout()

    def OnCopyButtonClick(self, ev):
        if wx.TheClipboard.Open():
            try:
                # get bitmap from clipboard
                if not wx.TheClipboard.IsSupported(wx.DataFormat(wx.DF_BITMAP)):
                    raise StandardError("No Bitmap in Clipboard")
                dataObject = wx.BitmapDataObject()
                if not wx.TheClipboard.GetData(dataObject):
                    raise StandardError("Failed to retrieve Bitmap")
                
            except StandardError, e:
                wx.MessageBox(str(e), "Error")
                
            else:
                # show bitmap in scrollwindow
                dc = wx.ClientDC(self.sceneEditor)
                bitmap = dataObject.GetBitmap()
                dc.DrawBitmap(bitmap, 30, 30, False)
                
            finally:
                # close clipboard again
                wx.TheClipboard.Close()

    def OnLoadButtonClock(self, ev):
        dc = wx.ClientDC(self.sceneEditor)
        bitmap = wx.Bitmap(r"/Users/robert/Desktop/test2.png")
        dc.DrawBitmap(bitmap, 30, 30, False)


class TestApp(wx.App):

    def OnInit(self):
        frame = EditFrame()
        frame.Show(True)
        self.SetTopWindow(frame)
        return True


if __name__ == "__main__":
    app = TestApp(redirect=False)
    app.MainLoop()
